package com.baturu.vin.byd.dal.dao;

import com.baturu.vin.byd.dto.BydPartsInfoDTO;
import com.baturu.vin.byd.dto.BydReplaceCodeDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;

public interface BydPartsInfoDAO {

    @Select({"<script>select distinct callout, name, partId, partNo, partsCode, carSystemId, dataGroupId, dataLegendId from byd_parts_info",
            "where dataLegendId in (select distinct dataLegendId from byd_subgroup",
            " where carTypeMjId = #{carTypeMjId})",
            "and partsCode in",
            "<foreach item='partsCode' index='index' collection='partsCodes' open='(' separator=',' close=')'>",
            "#{partsCode}",
            "</foreach>",
            "</script>"})
    List<BydPartsInfoDTO> getPartsInfoByCarTypeMjId(@Param("carTypeMjId") Integer carTypeMjId, @Param("partsCodes") List<String> partsCodes);

    @Select({"<script>select distinct callout, name, partId, partNo, partsCode, carSystemId, dataGroupId, dataLegendId from byd_parts_info",
            "where carSystemId = #{carSystemId}",
            "and partsCode in",
            "<foreach item='partsCode' index='index' collection='partsCodes' open='(' separator=',' close=')'>",
            "#{partsCode}",
            "</foreach>",
            "</script>"})
    List<BydPartsInfoDTO> getPartsInfoByCarSystemId(@Param("carSystemId") Integer carSystemId, @Param("partsCodes") List<String> partsCodes);

    @Select({"<script>select distinct callout, name, partId, partNo, partsCode, carSystemId, dataGroupId, dataLegendId from byd_parts_info",
            "where partsCode in",
            "<foreach item='partsCode' index='index' collection='partsCodes' open='(' separator=',' close=')'>",
            "#{partsCode}",
            "</foreach>",
            "</script>"})
    List<BydPartsInfoDTO> getPartsInfoByPartsCodes(@Param("partsCodes") List<String> partsCodes);

    @Select({"<script>select DISTINCT a.partsCode, c.partsCode as replacePartsCode from byd_parts_info as a",
            " join byd_parts_supersession as b on a.partId=b.oldPartId ",
            "join byd_parts_info as c on c.partId=b.newPartId",
            "where a.partsCode in ",
            "<foreach item='item' index='index' collection='partsCode' open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "</script>"})
    List<BydReplaceCodeDTO> queryReplaceCode(@Param("partsCode") Collection<String> partsCode);

}
